package com.example.androidhive;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.EditText;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

class MM extends Thread{
	JSONParser jsonParser = new JSONParser();
	private static String url_create_product2 ="http://opiekuj1.javaprovider.net/php/rezerwa.php";
	private static final String TAG_SUCCESS = "success";
	public void run(){
		CreateNewProductR aan =new CreateNewProductR();
		for (int i = 0; i < 20; i++) {
			try{
				Thread.sleep(3000);//aan.execute();
				List<NameValuePair> params = new ArrayList<NameValuePair>();
				params.add(new BasicNameValuePair("nazwa", "mm"));
				JSONObject json = jsonParser.makeHttpRequest(url_create_product2,
						"POST", params);
				
				// check log cat fro response
				//Log.d("Create Response", json.toString());

				// check for success tag
				try {
					int success = json.getInt(TAG_SUCCESS);

				} catch (JSONException e) {
					e.printStackTrace();
				}

				//return null;
			}
			catch(Exception e){
				
			}
		}
	}
	
}
class CreateNewProductR extends AsyncTask<String,String,String> {

	// Progress Dialog
	private ProgressDialog pDialog;

	JSONParser jsonParser = new JSONParser();
	EditText mojekontohaslo_;

	// url to create new product
	private static String url_create_product ="http://opiekuj1.javaprovider.net/php/logowanie.php";
	private static String url_create_product2 ="http://opiekuj1.javaprovider.net/php/rezerwa.php";

	// JSON Node names
	private static final String TAG_SUCCESS = "success";
	/**
	 * Before starting background thread Show Progress Dialog
	 * */
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	
	}

	/**
	 * Creating product
	 * */
	protected String doInBackground(String... args) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("nazwa", "mm"));
		JSONObject json = jsonParser.makeHttpRequest(url_create_product2,
				"POST", params);
		
		// check log cat fro response
		//Log.d("Create Response", json.toString());

		// check for success tag
		try {
			int success = json.getInt(TAG_SUCCESS);

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return null;
	}

	/**
	 * After completing background task Dismiss the progress dialog
	 * **/
	protected void onPostExecute(String file_url) {
		// dismiss the dialog once done
	}

}